package com.bw.zg3park2212.merchant

import android.app.TimePickerDialog
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.entity.MerchantAddParam
import com.bw.base.mvvm.BaseActivity
import com.bw.zg3park2212.R
import com.bw.zg3park2212.databinding.ActivityMerchantAddBinding
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat
import java.util.*

@AndroidEntryPoint
@Route(path = "/app/MerchantAddActivity")
class MerchantAddActivity : BaseActivity<ActivityMerchantAddBinding,MerchantViewModel>() {
    override fun intitView() {
        binding.tvTime.setOnClickListener {
            val calendar= Calendar.getInstance()
            TimePickerDialog(this, TimePickerDialog.OnTimeSetListener { view, hourOfDay, minute ->
                val hour=if (hourOfDay<10) "0"+hourOfDay else hourOfDay
                val min=if (minute<10) "0"+minute else minute
                binding.merEntryTime.setText(SimpleDateFormat("yyyy-MM-dd").format(System.currentTimeMillis())+" "+hour+":"+min)
            },calendar.get(Calendar.HOUR_OF_DAY),calendar.get(Calendar.MINUTE),true).show()
        }
        binding.check.setOnClickListener {
            var merchantAddParam= MerchantAddParam()
           merchantAddParam.applicationNumber=binding.merEnterpriseName.text.toString()
            merchantAddParam.contactName=binding.merContactName.text.toString()
            merchantAddParam.contactMethod=binding.merContactMethod.text.toString().toLong()
            merchantAddParam.entryTime=binding.merEntryTime.text.toString()
            merchantAddParam.applicationArea=binding.merApplicationArea.text.toString().toInt()
            merchantAddParam.entryPersonnel=binding.merEntryPersonnel.text.toString().toInt()
            viewmodel.getmerchanadd(merchantAddParam)
        }
    }

    override fun intitData() {
        viewmodel.merchanaddSuccse.observe(this){
            ToastUtils.showLong("申请成功")
            finish()
        }
    }

}